/*
 * thread_pool.h
 *
 *  Created on: 2015-5-15
 *      Author: likui
 */

#ifndef THREAD_POOL_H_
#define THREAD_POOL_H_

#include <stdbool.h>
#include <sys/types.h>
#include <pthread.h>
#include <semaphore.h>
#include "queue.h"

typedef struct thread_pool_t
{
	int				thread_number;		// 线程池中的线程数
	pthread_t		*thread_pids;		// 线程池数组

	int				max_request;		// 请求队列中允许的最大请求数
	queue_t			request_queue;		// 请求队列
	pthread_mutex_t	queue_mutex;	// 保护队列的互斥量

	sem_t			sem_request;		// 信号量，是否有任务需要处理
	bool			stop;				// 是否停止

}thread_pool_t;

thread_pool_t* thread_pool_create(int thread_num, int max_req);
bool thread_pool_init(thread_pool_t *thread_pool, int thread_num, int max_req);
void thread_pool_destroy(thread_pool_t **thread_pool);
bool thread_pool_append(thread_pool_t *thread_pool ,http_conn_t *http_conn);
void thread_pool_run(thread_pool_t *thread_pool);
void *thread_pool_worker(void *arg);

#endif /* THREAD_POOL_H_ */
